import { defineStore } from 'pinia'
import { RouteLocationNormalized } from 'vue-router'
import { StateType } from '@/interfaces/StroeType'

export default defineStore('user', {
  // other options...
  state: (): StateType => {
    return {
      // 所有这些属性都将自动推断其类型
      name: 'ldh',
      routerData: [
        {
          path: '/',
          name: 'pagehome',
          meta: { title: '首页', icon: 'el-icon-menu' },
        },
      ],
      path: '/',
    }
  },
  actions: {
    GETROUTERDAT(to: RouteLocationNormalized) {
      if (to.name) {
        this.routerData.some((item) => item.name === to.name) || this.routerData.push(to)
      }
    },
    REMOVEROUTERTOP(val: string) {
      this.routerData = this.routerData.filter((item) => item.name !== val)
    },
  },
  getters: {
    keepRouterData(): Array<string> {
      const result: Array<string> = this.routerData.map((item) => item.name) as Array<string>
      return result
    },
  },
})
